<?php 
$str_tag = "";
if(isset($_GET['id'])){

    $id = (int) $_GET['id'];

    require_once "model/Dishes.php";

    $model = new Dishes;

    $detail = $model->getDetailDishes($id);

    $type = $detail['type'];

}
?>

<script type="text/javascript" src="static/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="static/ckfinder/ckfinder.js"></script>
<script type="text/javascript" src="static/js/ajaxupload.js"></script>
<div class="row">

    <div class="col-md-8">

        <form method="post" action="controller/Dishes.php">            

        <!-- Custom Tabs -->

        <button class="btn btn-primary btn-sm" onclick="location.href='index.php?mod=dishes&act=list'">Danh sách thức ăn</button>

        <div style="clear:both;margin-bottom:10px"></div>
        <div class="box box-primary">    
         <div class="box-header">

                <h3 class="box-title"><?php echo ($id > 0) ? "Cập nhật" : "Tạo mới" ?> thức ăn <?php echo ($id > 0) ? " : ".$detail['title'] : ""; ?></h3>

                <?php if($id> 0){ ?>

                <input type="hidden" value="<?php echo $id; ?>" name="id" />

                <?php } ?>

            </div><!-- /.box-header -->

        <div class="box-body">            
            <div class="form-group">

                <label>Loại <span class="required"> ( * ) </span></label>

                <select class="form-control required" name="type" id="type">

                    <option value="0">---chọn---</option>

                    <option value="1" <?php echo ($detail['type']==1) ? "selected" : ""; ?>>Thức ăn</option>

                    <option value="2" <?php echo ($detail['type']==2) ? "selected" : ""; ?>>Nước uống</option>

                </select>

            </div>    
            <div class="form-group">

                    <label>Tên<span class="required"> ( * ) </span></label>

                    <input type="text" name="name" class="form-control required" value="<?php echo isset($detail['name'])  ? $detail['name'] : "" ?>">

            </div>  
            <div class="form-group">

                    <label>Tên tiếng anh<span class="required"> ( * ) </span></label>

                    <input type="text" name="name_en" class="form-control required" value="<?php echo isset($detail['name_en'])  ? $detail['name_en'] : "" ?>">

            </div>       
            <div class="form-group">

                    <label>Giá<span class="required"> ( * ) </span></label>

                    <input type="text" name="price" class="form-control required" value="<?php echo isset($detail['price'])  ? $detail['price'] : "" ?>">

            </div>                  
            <div class="form-group">

                    <label>Hình đại diện &nbsp;&nbsp;&nbsp;</label>

                    <input type="hidden" name="image_url" id="image_url" class="form-control" value="<?php echo isset($detail['image_url'])  ? $detail['image_url'] : "" ?>">    

                    <img src="<?php echo $detail['image_url']!=""  ? "../".$detail['image_url'] : "" ?>" id="hinh_dai_dien" width="400" style="<?php echo $detail['image_url']!=""  ? "" : "display:none;" ?>margin-top:5px"/>

                    <button class="btn btn-primary" type="button" onclick="BrowseServer('Images:/','image_url')" >Chọn ảnh</button>

                    <div style="color:red;font-size:19px">
                    Thức ăn : 470 x 376 px<br />
                    Nước uống : 303 x 243 px
                    <br />
                    </div>


                </div>  
            <div class="form-group">

                <label>Mô tả <span class="required"> ( * ) </span></label>                        

                <textarea rows="5" id="description" class="form-control" name="description"><?php if(isset($detail['description'])) echo $detail['description']; ?></textarea>

            </div>                      
            <div class="form-group">

                <label>Thành phần <span class="required"> ( * ) </span></label>                        

                <textarea rows="5" id="components" class="form-control" name="components"><?php if(isset($detail['components'])) echo $detail['components']; ?></textarea>

            </div>           

            <div class="button">

                <button class="btn btn-primary btnSave" type="submit">Save</button>

                <button class="btn btn-primary" type="reset">Cancel</button>

            </div>

           

        </div><!-- nav-tabs-custom -->
        </div>
    </form>

    </div><!-- /.col --> 

</div>

<link href="<?php echo STATIC_URL; ?>css/jquery-ui.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">

function split(val) {
    return val.split(/;\s*/);
}

function extractLast(term) {
    return split(term).pop();
}
function BrowseServer( startupPath, functionData ){    
    var finder = new CKFinder();
    finder.basePath = 'ckfinder/'; //Đường path nơi đặt ckfinder
    finder.startupPath = startupPath; //Đường path hiện sẵn cho user chọn file
    finder.selectActionFunction = SetFileField; // hàm sẽ được gọi khi 1 file được chọn
    finder.selectActionData = functionData; //id của text field cần hiện địa chỉ hình
    //finder.selectThumbnailActionFunction = ShowThumbnails; //hàm sẽ được gọi khi 1 file thumnail được chọn    
    finder.popup(); // Bật cửa sổ CKFinder
} //BrowseServer

function SetFileField( fileUrl, data ){
    document.getElementById( data["selectActionData"] ).value = fileUrl;
    $('#hinh_dai_dien').attr('src',fileUrl).show();
}
</script>
<script type="text/javascript">
var editor = CKEDITOR.replace( 'description',{
    uiColor : '#9AB8F3',
    language:'vi',
    height:200,
    width:700,
    skin:'office2003',
      filebrowserImageBrowseUrl: 'ckfinder/ckfinder.html?Type=Images',
        filebrowserFlashBrowseUrl: 'ckfinder/ckfinder.html?Type=Flash',
        filebrowserImageUploadUrl: 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
        filebrowserFlashUploadUrl: 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash',
    toolbar:[ 

    ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
    ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],
    ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
    ['Link','Unlink','Anchor','Styles','Format','Font','FontSize'],    
    
    ['TextColor','BGColor'],    
    ]
}); 
var editor1 = CKEDITOR.replace('components',{
    uiColor : '#9AB8F3',
    language:'vi',
    height:200,
    width:700,
    skin:'office2003',
      filebrowserImageBrowseUrl: 'ckfinder/ckfinder.html?Type=Images',
        filebrowserFlashBrowseUrl: 'ckfinder/ckfinder.html?Type=Flash',
        filebrowserImageUploadUrl: 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
        filebrowserFlashUploadUrl: 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash',
    toolbar:[ 

    ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
    ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],
    ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
    ['Link','Unlink','Anchor','Styles','Format','Font','FontSize'],    
    
    ['TextColor','BGColor'],    
    ]
});      
</script>